//
//  FTMainController.swift
//  Weibo
//
//  Created by 方焘 on 16/6/11.
//  Copyright © 2016年 taofang. All rights reserved.
//



import UIKit



class FTMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let tabBar = FTTabBar()
        tabBar.FTDelegate = self
        setValue(tabBar, forKey: "TabBar")
        
        
        self.addChildViewController(FTHomeController(), title: "首页", imageName: "tabbar_home")
        self.addChildViewController(FTMessageController(), title: "消息", imageName: "tabbar_message_center")
        self.addChildViewController(FTDiscoverController(), title: "发现", imageName: "tabbar_discover")
        self.addChildViewController(FTProfileController(), title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String)  {
        childController.navigationItem.title = title
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: ThemeColor], forState: UIControlState.Selected)
        self.addChildViewController(UINavigationController(rootViewController: childController))
    }

}

// MARK: FTTabBarDelegate
extension FTMainController : FTTabBarDelegate {
    func didClickCompseButton() {
        let composeController = FTComposeController()
        
        self.presentViewController(UINavigationController(rootViewController: composeController), animated: true, completion: nil)
    }
}
